Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/i18n utils unreverted #47492

Closed
wants to merge 10 commits into from
Closed

Update/i18n utils unreverted #47492

wants to merge 10 commits into from

Conversation

lsl
Copy link
Contributor

@lsl lsl commented Nov 17, 2020

Context: #47352 (comment)

Follows up on @p-jackson's #47446 to introduce useLocale, incorporates some changes from #47358 to decouple i18n-utils from getLocaleSlug (i18n-calypso package), but instead of replacing getLocaleSlug with react-i18n's useI18n, it uses its own useLocale.

i18n-utils is now completely free of all deps but does expect the LocaleProvider to be configured.

warning: Pretty sure I haven't got this set up right yet. Manual testing was showing localizeUrl wasn't working in the /new/domains/es gutenboarding context.

Please suggest anything you see that can be dropped from this PR without causing any knock on effects - e.g. we can probably drop changes to domain-picker.

Changes proposed in this Pull Request

Testing instructions

Fixes #

@matticbot
Copy link
Contributor

return {
__: i18n.__.bind( i18n ),
_n: i18n._n.bind( i18n ),
_nx: i18n._nx.bind( i18n ),
_x: i18n._x.bind( i18n ),
isRTL: i18n.isRTL.bind( i18n ),
i18nLocale,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to roll this change back and keep it around for a bit - breaking change. (and widely used in calypso) ... What's -alpha mean in the version number? Is that basically like saying this isn't semver?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's -alpha mean in the version number? Is that basically like saying this isn't semver?

That's how pre-release versions are denoted according to SemVer's specs. Ref: https://semver.org/#spec-item-9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So safe to break backward compat here then, thanks for the link 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure that @automattic/react-i18n is used anywhere outside of a8c either so I was just planning to udpate all the uses. It looks like there is a package on the npm registry but it's private.

@lsl lsl requested a review from yuliyan November 17, 2020 09:19
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Nov 17, 2020
@lsl lsl requested a review from p-jackson November 17, 2020 09:19
@matticbot
Copy link
Contributor

matticbot commented Nov 17, 2020

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~593 bytes added 📈 [gzipped])

name                   parsed_size           gzip_size
entry-main                  +674 B  (+0.0%)      +99 B  (+0.0%)
entry-login                 +664 B  (+0.1%)     +113 B  (+0.0%)
entry-domains-landing       +664 B  (+0.1%)     +181 B  (+0.1%)
entry-gutenboarding         +596 B  (+0.0%)     +200 B  (+0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Async-loaded Components (~52 bytes added 📈 [gzipped])

name                                           parsed_size           gzip_size
async-load-calypso-blocks-editor-launch-modal        -17 B  (-0.0%)      +52 B  (+0.1%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

Copy link
Member

@p-jackson p-jackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. I still need to make some changes to my PR since it currently breaks the build I believe, which means that some of these changes will probably disappear after a rebase.

client/components/calypso-i18n-provider/index.tsx Outdated Show resolved Hide resolved
return {
__: i18n.__.bind( i18n ),
_n: i18n._n.bind( i18n ),
_nx: i18n._nx.bind( i18n ),
_x: i18n._x.bind( i18n ),
isRTL: i18n.isRTL.bind( i18n ),
i18nLocale,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure that @automattic/react-i18n is used anywhere outside of a8c either so I was just planning to udpate all the uses. It looks like there is a package on the npm registry but it's private.

@@ -132,3 +128,14 @@ export function localizeUrl( fullUrl: string, toLocale?: Locale ): string {
// Nothing needed to be changed, just return it unmodified.
return fullUrl;
}

export function useLocalizeUrl(): ( fullUrl: string, locale?: Locale ) => string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Co-authored-by: Philip Jackson <p-jackson@live.com>
Copy link
Member

@yuliyan yuliyan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few small remarks, but overall it LGTM 🚀

packages/i18n-utils/src/localize-url.ts Show resolved Hide resolved
@@ -25,7 +27,11 @@ const CalypsoI18nProvider: React.FunctionComponent = ( { children } ) => {
};
}, [] );

return <I18nProvider localeData={ localeData }>{ children }</I18nProvider>;
return (
<LocaleProvider localeSlug={ localeSlug || 'en' }>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use config( 'i18n_default_locale_slug' ) for fallback instead of 'en' string literal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, TIL! There's some other places I can use this config value too 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposed and used the hard coded one in i18n-utils, I think we need to strip these i18n config values from calypso usage and rely on the utils package unless we want to configure LocaleProvider with the configuration as well?

This is done in #47613

@lsl lsl mentioned this pull request Nov 20, 2020
46 tasks
@lsl
Copy link
Contributor Author

lsl commented Nov 20, 2020

#47612
#47613

@lsl lsl closed this Nov 20, 2020
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Nov 20, 2020
@sirreal sirreal deleted the update/i18n-utils-unreverted branch January 14, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants